<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.utils.SiteHelper" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.user.entity.UserLevel" %>
<%@ page import="org.apache.commons.collections.CollectionUtils" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<!doctype html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/bootstrap-datepicker3.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/list.css">
    <script type="text/javascript">
        //document.getElementsByTagName("html")[0].style.width=screen.availWidth/100+"px";
        document.getElementsByTagName("html")[0].style.fontSize=screen.availWidth/200+"px";
    </script>
    <style type="text/css">
        .border{
            border:1px solid red;
        }
    </style>
</head>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <%--Title--%>
                        <div class="box-header">
                            <h3 class="box-title">利润报表</h3>
                        </div>
                        <!-- /.box-header -->
                        <div>
                            <%
                                UserLevel level = (UserLevel) request.getAttribute("level");

                                Integer count = (Integer) request.getAttribute("count");
                                Double amount = (Double) request.getAttribute("amount");
                                Double fee = (Double) request.getAttribute("fee");
                                Double spFee = (Double) request.getAttribute("spFee");
                                Double agentProfit = (Double) request.getAttribute("agentProfit");
                                Double profit = (Double) request.getAttribute("profit");

                                String from = (String) request.getAttribute("from");
                                String to = (String) request.getAttribute("to");
                                Long cpId = (Long) request.getAttribute("cpId");
                                String cpName = (String) request.getAttribute("cpName");
                                Long agentId = (Long) request.getAttribute("agentId");
                                String contract = (String) request.getAttribute("contract");
                                Integer channel = (Integer) request.getAttribute("channel");
                            %>
                                    <form id="searchForm" class="" action="/statement/all">
                                        <div class="new-group date form_datetime">
                                            <label for="from">开始日期：</label>
                                            <input type="text" class="" id="from" name="from" readonly
                                                   value="<%= StringUtils.isNotBlank(from) ?from:""%>">
                                        </div>
                                        <div class="new-group date form_datetime">
                                            <label for="to">结束日期：</label>
                                            <input type="text" class="" id="to" name="to" readonly
                                                   value="<%= StringUtils.isNotBlank(to) ?to:""%>">
                                        </div>
                                        <div class="new-group">
                                            <label for="cpId">商户 ID：</label>
                                            <input type="text" class="" id="cpId" name="cpId"
                                                   value="<%= null!=cpId ?cpId:""%>">
                                        </div>
                                        <div class="new-group">
                                            <label for="cpName">商户名称：</label>
                                            <input type="text" class="" id="cpName" name="cpName"
                                                   value="<%= StringUtils.isNotBlank(cpName) ?cpName:""%>">
                                        </div>
                                        <%if (level == UserLevel.ADMIN) {%>
                                        <div class="new-group">
                                            <label for="agentId">代理商 ID：</label>
                                            <input type="text" class="l" id="agentId" name="agentId"
                                                   value="<%= null!=agentId ?agentId:""%>">
                                        </div>
                                        <div class="new-group">
                                            <label for="contract">代理商名称：</label>
                                            <input type="text" class="" id="contract" name="contract"
                                                   value="<%= StringUtils.isNotBlank(contract) ?contract:""%>">
                                        </div>
                                        <%}%>
                                        <div class="new-group">
                                            <label for="channel">支付方式：</label>
                                            <select class="" id="channel" name="channel">
                                                <%
                                                    Map<Integer, String> channelMap = (Map<Integer, String>) request.getAttribute("channels");
                                                    for (Integer key : channelMap.keySet()) {
                                                        String value = channelMap.get(key);
                                                %>
                                                <option value="<%=key%>"
                                                        <% if (null != channel && channel.equals(key)) {%>
                                                        selected="selected"<%}%>>
                                                    <%=value%>
                                                </option>
                                                <%}%>
                                            </select>
                                        </div>
                                        <div class="button-group">
                                        <button type=" submit" class="button back-green" id="btnSearch" style="font-size: 1rem">查询</button>
                                        <a href="" id="btnDownload" download="利润报表.xls"
                                           target="_blank"><button type="button" class="button back-green" style="font-size: 1rem">导出</button></a>
                                        </div>
                                    </form>
                                </div>
                            <div style="clear: both;"></div>
                                <div class="box box-danger">
                                    <div class="box-header">
                                        <h3 class="box-title">利润统计</h3>
                                    </div>
                                    <div class="tableContent">
                                        <table id="pLst" width="100%" cellpadding="0" cellspacing="0" border="1">
                                            <thead>
                                            <tr>
                                                <th width="6%">日期</th>
                                                <th width="6%">商户 ID</th>
                                                <th width="15%">商户名称</th>
                                                <%if (level == UserLevel.ADMIN) {%>
                                                <th width="6%">代理商 ID</th>
                                                <th width="15%">代理商名称</th>
                                                <%}%>
                                                <th width="8%">支付方式</th>
                                                <th width="8%">总笔数</th>
                                                <th width="8%">总金额</th>
                                                <th width="6%">商户费率</th>
                                                <th width="6%">商户手续费</span>
                                                </th>
                                                <%if (level == UserLevel.ADMIN) {%>
                                                <th width="6%">SP 手续费</th>
                                                <%}%>
                                                <th width="6%">代理商费率</th>
                                                <th width="6%">代理商分润</th>
                                                <%if (level == UserLevel.ADMIN) {%>
                                                <th width="8%">纯利润</th>
                                                <%}%>
                                            </tr>
                                            <tr>
                                                <th width="6%"></th>
                                                <th width="6%"></th>
                                                <th width="6%"></th>
                                                <%if (level == UserLevel.ADMIN) {%>
                                                <th width="6%"></th>
                                                <th width="6%"></th>
                                                <%}%>
                                                <th width="8%"></th>
                                                <th width="8%"><span style="color: green;"><%=count%></span></th>
                                                <th width="8%"><span style="color: green;"><%=SiteHelper.formatMoney(amount, 100.0)%></span>
                                                </th>
                                                <th width="6%"></th>
                                                <th width="6%"><span style="color: green;"><%=SiteHelper.formatMoney(fee, 100.0)%></span>
                                                </th>
                                                <%if (level == UserLevel.ADMIN) {%>
                                                <th width="6%"><span style="color: green;"><%=SiteHelper.formatMoney(spFee, 100.0)%></span>
                                                </th>
                                                <%}%>
                                                <th width="6%"></th>
                                                <th width="6%"><span style="color: green;"><%=SiteHelper.formatMoney(agentProfit, 100.0)%></span>
                                                </th>
                                                <%if (level == UserLevel.ADMIN) {%>
                                                <th width="8%"><span style="color: green;"><%=SiteHelper.formatMoney(profit, 100.0)%></span>
                                                </th>
                                                <%}%>

                                            </tr>
                                            </thead>
                                            <tbody>
                                            <%
                                                List<List<String>> list = (List<List<String>>) request.getAttribute("lst");
                                                if (CollectionUtils.isNotEmpty(list)) {
                                                    for (List<String> p : list) {
                                            %>
                                            <tr>
                                                <td>
                                                    <%=p.get(0)%>
                                                </td>
                                                <td>
                                                    <%=p.get(1)%>
                                                </td>
                                                <td>
                                                    <%=p.get(2)%>
                                                </td>
                                                <%if (level == UserLevel.ADMIN) {%>
                                                <td>
                                                    <%=p.get(3)%>
                                                </td>
                                                <td>
                                                    <%=p.get(4)%>
                                                </td>
                                                <%}%>
                                                <td>
                                                    <%=p.get(5)%>
                                                </td>
                                                <td>
                                                    <%=p.get(6)%>
                                                </td>
                                                <td>
                                                    <%=p.get(7)%>
                                                </td>
                                                <td>
                                                    <%=p.get(8)%>
                                                </td>
                                                <td>
                                                    <%=p.get(9)%>
                                                </td>
                                                <%if (level == UserLevel.ADMIN) {%>
                                                <td>
                                                    <%=p.get(10)%>
                                                </td>
                                                <%}%>
                                                <td>
                                                    <%=p.get(11)%>
                                                </td>
                                                <td>
                                                    <%=p.get(12)%>
                                                </td>
                                                <%if (level == UserLevel.ADMIN) {%>
                                                <td>
                                                    <%=p.get(13)%>
                                                </td>
                                                <%}%>
                                                <%
                                                    }
                                                %>
                                            </tr>
                                            <%
                                            } else {
                                            %>
                                            <tr>
                                                <td colspan="<%=level== UserLevel.ADMIN? 14: 10%>">未找到数据</td>
                                            </tr>
                                            <% }%>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>

                                <%if (level == UserLevel.ADMIN) {%>
                                <div class="box box-info">
                                    <div class="box-header ">
                                        <h3 class="box-title">提现统计</h3>
                                    </div>
                                    <div class="tableContent">
                                        <table class="" width="100%" cellpadding="0" cellspacing="0" border="1">
                                            <thead>
                                            <tr>
                                                <th width="10%">日期</th>
                                                <th width="10%">提现类型</th>
                                                <th width="10%">提现金额</th>
                                                <th width="10%">提现笔数</th>
                                                <th width="15%">手续费总收入</th>
                                            </tr>
                                            <tr>
                                                <%
                                                   Double fees=(Double)request.getAttribute("feesum");
                                                   int countsum=(int) request.getAttribute("countsum");
                                                %>
                                                <th width="10%"></th>
                                                <th width="10%"></th>
                                                <th width="10%"></th>
                                                <th width="10%" style="color: green;"><%=countsum%></th>
                                                <th width="15%" style="color: green;"><%=SiteHelper.formatMoney(fees,100.0)%></th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <%
                                                list = (List<List<String>>) request.getAttribute("withdrawLst");
                                                if (CollectionUtils.isNotEmpty(list)) {
                                                    for (List<String> p : list) {
                                            %>
                                            <tr>
                                                <td>
                                                    <%=p.get(0)%>
                                                </td>
                                                <td>
                                                    <%=p.get(1)%>
                                                </td>
                                                <td>
                                                    <%=p.get(2)%>
                                                </td>
                                                <td>
                                                    <%=p.get(3)%>
                                                </td>
                                                <td>
                                                    <%=p.get(4)%>
                                                </td>
                                                <%}%>
                                            </tr>
                                            <%
                                            } else {
                                            %>
                                            <tr>
                                                <td colspan="4">未找到数据</td>
                                            </tr>
                                            <% }%>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <%}%>
                            </div>
                        </div>
                    </div>

    </section>

</div>
<jsp:include page="foot.jsp"></jsp:include>
</div>

</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.dataTables.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/bootstrap-datepicker.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/bootstrap-datepicker.zh-CN.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>

<script>
    $(function () {
        $('#from, #to').datepicker({
            format: "yyyy-mm-dd",
            todayBtn: true,
            clearBtn: true,
            language: "zh-CN"
        });

        initDownload();
    });

    $("#searchForm input, #searchForm select").change(initDownload);
    function initDownload() {
        $("#btnDownload").attr("href", "/statement/all/export?" + $("#searchForm").serialize());
        $("#btnDownload").attr("download", "利润报表 " + $("#from").val() + "至" + $("#to").val() + ".xls");
    }
</script>
</body>
</html>

